<template>
  <div>
    <tableComponents :pagination="{ currentPage, pageSize, total: list.all_num }" @handleCurrentChange="handleCurrentChange"
        @handleSizeChange="handleSizeChange" @sendUserSearch="getSearch" :searchData="userSearchData" :isHaveExport="false" :isHaveAdd="false">
      <template v-slot:table>
        <el-table ref="multipleTable" :data="list.data" v-loading="loading" stripe header-row-class-name="head_color" tooltip-effect="dark"
            style="width: 99.9%" @selection-change="handleSelectionChange">
          <el-table-column label="会员" min-width="100" align="center">
            <template slot-scope="scope">
              <div class="tc">
                <router-link :to="'/index/user/user_info?id=' + scope.row.uid">
                  <img style="width:50px;height:50px" :src="$fnc.getImgUrl(scope.row.avatar)" class="user_img" />
                </router-link>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="会员信息" min-width="160">
            <template slot-scope="scope">
              <div class="user_table">
                <router-link :to="'/index/user/user_info?id=' + scope.row.uid">
                  <span>用户昵称：</span>
                  <small>{{ scope.row.nickname || "----" }}</small>
                  <br />
                  <span>会员账号：</span>
                  <small>{{ scope.row.username }}</small>
                  <div v-if="scope.row.supplier_company_tel">
                    <span>申请电话号码：</span>
                    <small>{{ scope.row.supplier_company_tel }}</small>
                  </div>
                </router-link>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="店铺信息" min-width="160">
            <template slot-scope="scope">
              <div class="user_table">
                <span>店铺名称：</span>
                <small>{{ scope.row.title }}</small>
                <br />
                <span>申请地址：</span>
                <small>{{
                  $fnc.deleteNumber(
                    scope.row.province +
                      scope.row.city +
                      scope.row.area +
                      scope.row.town
                  ) + scope.row.add
                }}</small>
                <br />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="法人信息" min-width="160">
            <template slot-scope="scope">
              <div class="user_table">
                <span>法人姓名：</span>
                <small>{{ scope.row.name || "----" }}</small>
                <br />
                <span>身份证号：</span>
                <small>{{ scope.row.card }}</small>
                <br />
              </div>
            </template>
          </el-table-column>

          <el-table-column label="申请时间" min-width="100">
            <template slot-scope="scope">{{
              scope.row.created_time | getTimeFormat
            }}</template>
          </el-table-column>

          <el-table-column label="审核状态" min-width="100">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.is_check == 1" type="success" effect="dark">已审核</el-tag>
              <el-tag v-else-if="scope.row.is_check == 2" type="danger" effect="dark">驳回</el-tag>
              <el-tag v-else type="warning" effect="dark">未审核</el-tag>
            </template>
          </el-table-column>

          <el-table-column label="操作" align="center" min-width="200">
            <template slot-scope="scope">
              <el-button :loading="$store.state.isLoading" type="primary" size="mini" @click="handleSwitch(scope.row)">审核</el-button>
              <el-button :loading="$store.state.isLoading" type="primary" size="mini" @click="showEditDialog(scope.row.id)">编辑</el-button>
              <el-button :loading="$store.state.isLoading" type="primary" size="mini" @click="toSupplierDetails(scope.row.id)">查看</el-button>
              <el-button :loading="$store.state.isLoading" size="mini" @click="deleteNew(scope.$index, scope.row.id)" type="danger">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <template v-slot:footerLeft>
        <a class="aBtn aBtn_1 aBtn_lan2" @click="delSelection">删除</a>
      </template>
    </tableComponents>

    <MsgEdit @parent="reload" :show.sync="show" :editId="editId" :clickNum="clickNum"></MsgEdit>

    <el-dialog :close-on-click-modal="false" title="审核供应商" :modal-append-to-body="false" :visible.sync="show_supplier" class="tl size_13"
        width="800px">
      <SupplierUpdate v-if="show_supplier" :isCheckSupplier="false" :row="row" @openThis="getOpenThis"></SupplierUpdate>
    </el-dialog>
  </div>
</template>
<script>
import MsgEdit from "@/components/user/checksupplier_edit.vue";
import SupplierUpdate from "@/components/user/SupplierUpdate.vue"; //编辑与加入供应商
import { checkUserAgentSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  data () {
    return {
      userSearchData: checkUserAgentSearchData,
      show: false,
      loading: false,
      list: [],
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      editId: "",
      multipleSelection: "",
      arr: [],
      visible: false,
      clickNum: 0,
      updataIndex: "",
      searchAll: {},
      show_supplier: false,
      row: {}
    };
  },
  components: {
    MsgEdit,
    SupplierUpdate
  },
  methods: {
    getOpenThis () {
      this.show_supplier = false;
      this.getNewsAll(this.searchAll);
    },
    toSupplierDetails (id) {
      this.$store.commit("addbreadcrumbs", {
        title: "供应商详情",
        url: "/index/user/checksupplierdetails?id=" + id
      });
      this.$router.push("/index/user/checksupplierdetails?id=" + id);
    },
    getSearch (obj) {
      this.searchAll = obj;
      this.getNewsAll(obj);
    },
    getNewsAll (data) {
      this.loading = true;
      var params = {};
      data = data || {};
      data.page = data.page || 1;
      data.page_size = data.page_size || 10;
      params = data;
      this.$api.getUser.getSupplierList(params).then(res => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    handleSizeChange (val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
      // console.log(`每页 ${val} 条`);
    },
    handleCurrentChange (val) {
      // console.log(`当前页:`+val)
      this.currentPage = val;
      var params = this.searchAll;
      params.page = val;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
    },
    handleSwitch (row) {
      //审核
      this.$api.getSupplier.checkSupplier({ id: row.id }).then(res => {
        if (res.data.code == 200) {
          // this.row=res.data.result;
          this.$set(this, "row", res.data.result);
          this.show_supplier = true;
          console.log(this.row);
        }
      });
    },
    handleSelectionChange (val) {
      //多选框赋值
      this.multipleSelection = val;
    },
    delSelection () {
      //删除
      var str = "";
      for (var i in this.multipleSelection) {
        str += this.multipleSelection[i].id + "@";
      }
      str = str.slice(0, -1);
      var data = { id_str: str };

      this.$api.getUser.supplierDel(data).then(res => {
        if (res.data.code == 200) {
          this.getNewsAll(this.searchAll);
        }
      });
    },
    deleteNew (index, id) {
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          var data = { id_str: id };

          this.$api.getUser.supplierDel(data).then(res => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
              console.log(this.list);
              this.getNewsAll();
            } else {
              this.$swal("删除失败！", "出错啦！", "success");
            }
          });
        }
      });
    },
    showEditDialog (id) {
      this.show = true;
      this.editId = id;
      this.clickNum++;
    },
    reload (id) {
      this.getNewsAll(this.searchAll);
    }
  },
  created () {
    this.getNewsAll(this.searchAll);
  }
};
</script>

<style lang="less" scoped>
thead > tr > th {
  height: 45px;
  line-height: 45px;
}
td,
th {
  border: 1px solid #e1e3e4;
  font-size: 12px;
}
th {
  background: #f8f8f8;
  font-weight: normal;
  color: #323437;
}
td {
  height: 75px;
  color: #000;
}
.caozuo {
  padding-left: 50px;
}
.pl {
  padding-left: 15px;
}
.chkBox {
  display: block;
  margin: 0 auto;
  width: 18px;
  height: 18px;
  background: #fff;
}
.aBtn_1 {
  padding: 10px;
}
</style>
